<template>
	<view class="recharge">
		<view class="card">
			<view class="top">
				输入金额(元)
			</view>
			<view class="inp">
				<view class="left">
					￥
				</view>
				<view class="right">
					<input type="number" v-model="price">
				</view>
				<view class="btn" @click="recharge">
					提回
				</view>
			</view>
			<view class="doMoney">
				当前余额{{ableMoneny}}元
			</view>
		</view>
	</view>
</template>
<script>
	import {
		getPhoneCode,
		getTwoUserList,
		getMoneny,
		idCardOCR,
		rechargeCode,
		rechargePay,
		withDraw
	} from '../../common/api/blank.js';
	import {
		_showLoading,
		_showToast,
		_showModal
	} from '../../common/js/util.js'
	export default {
		data() {
			return {
				price: "",
				batId: "",
				ableMoneny: "",
				phone: "",
				orgId: "",
				isCallBack: false, //是否正在提回
			}
		},
		onBackPress(options) {
			if (options.from === 'navigateBack') {
				return false
			}
			this.back();
			return true
		},
		onLoad(option) {
			this.orgId = option.orgId
			this.batId = option.batId
			this.phone = option.phone

		},
		async onShow() {
			uni.showLoading({
				title: "当前余额获取中",
				mask:true
			})
			try{
				const res = await getMoneny({
					batId: this.batId,
					orgId: this.orgId
				})
				if (res.code == 0) {
					uni.hideLoading()
					this.ableMoneny = res.data.balance
				} else {
					uni.hideLoading()
					_showModal("温馨提示!",res.msg)
				}
			}catch(e){
				//TODO handle the exception
				uni.hideLoading()
				_showModal("温馨提示!",e)
			}
			
		},
		components: {

		},
		methods: {
			back() {
				var pages = getCurrentPages();
				uni.navigateBack({
					delta: pages.length - 2
				})
			},
			async recharge() {
				if (this.isCallBack) {
					return
				}
				this.isCallBack = true
				if (this.price) {
					uni.showLoading({
						title: "短信发送中",
						mask:true
					})
					try {
						const res = await withDraw({
							batId: this.batId,
							amount: this.price,
							orgId: this.orgId
						})
						// console.log(res)
						uni.hideLoading()
						this.isCallBack = false
						if (res.code == 0) {
							
							uni.navigateTo({
								url: `/pageBlank/callBackVifis/callBackVifis?price=${this.price}&batId=${this.batId}&orderNo=${res.data.orderNo}&msgCodeSeq=${res.data.msgCodeSeq}&phone=${this.phone}&orgId=${this.orgId}`
							})
						} else {
							_showToast(res.msg)
						}
					} catch (e) {
						//TODO handle the exception
						uni.hideLoading()
						this.isCallBack = false
					}


				} else {
					uni.hideLoading()
					this.isCallBack = false
					_showToast("提回金额不能为空")
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		height: 100%;
		width: 100%;
	}

	page-body {
		height: 100%;
		width: 100%;
	}

	.recharge {
		box-sizing: border-box;
		padding: 70rpx 30rpx 0rpx 30rpx;
		height: 100%;

		.card {
			width: 690rpx;
			height: 273rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 3rpx 26rpx 1rpx rgba(0, 0, 0, 0.06);
			border-radius: 6rpx 6rpx 6rpx 6rpx;
			opacity: 1;
			padding-top: 28rpx;
			box-sizing: border-box;

			.doMoney {
				height: 35rpx;
				font-size: 24rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #519FF4;
				line-height: 35rpx;
				margin-left: 32rpx;
				margin-top: 20rpx;
			}

			.top {
				height: 46rpx;
				font-size: 32rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #40424E;
				line-height: 46rpx;

				margin-left: 32rpx;
				margin-bottom: 26rpx;
			}

			.inp {
				display: flex;
				margin-left: 32rpx;
				border-bottom: 1rpx solid #ccc;

				.btn {
					width: 148rpx;
					height: 72rpx;
					background: #3478F5;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					opacity: 1;
					font-size: 32rpx;
					font-family: Source Han Sans CN-Light, Source Han Sans CN;
					font-weight: 300;
					color: #FFFFFF;
					line-height: 72rpx;
					text-align: center;
					margin-bottom: 15rpx;
					margin-left: 10rpx;
				}

				.left {
					width: 46rpx;
					height: 66rpx;
					font-size: 46rpx;
					font-family: Source Han Sans CN-Medium, Source Han Sans CN;
					font-weight: 500;
					color: #40424E;
					line-height: 66rpx;
				}

				.right {
					width: calc(100% - 204rpx);
					height: 66rpx;
					line-height: 66rpx;

					font-family: Source Han Sans CN-Medium, Source Han Sans CN;
					font-weight: 500;
					color: #40424E;

					input {
						width: 100%;
						height: 66rpx;
						font-size: 46rpx;
					}
				}
			}
		}
	}
</style>